﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddUser.aspx.cs" Inherits="ShowRoom.admin.AddUser" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="css/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <center>
      <div style="width:100%;text-align:center;color:#C794BA;font-weight:bold;margin-bottom:10px;margin-top:15px;"><asp:Label ID="lblTil" runat="server" Text="THÊM MỚI NHÂN VIÊN"></asp:Label></div>       
        <table id="tblMaster" runat="server" bordercolor="#E1E1E1"  border="1" cellpadding="0" cellspacing="0" width="90%"
            style="border-collapse: collapse;">              
            <tr>
                <td style="width: 20%;text-align:right;padding-right:10px;height:30px"  nowrap>
                    Họ và tên <font color="red">*</font>:</td>
                <td style="width: 80%; text-align: left;padding-left:5px">
                    <asp:TextBox ID="txtTen" CssClass="cssTextBox" onblur="CheckName(this);" Width="70%" runat="server"></asp:TextBox></td>
            </tr>
          
            <tr>
                <td style="width: 20%;text-align:right;padding-right:10px;height:30px"  nowrap>
                    Tên đăng nhập  <font color="red">*</font>:</td>
                <td style="width: 80%; text-align: left;padding-left:5px" > <asp:TextBox ID="txtuser" onblur="CheckUser(this);" CssClass="cssTextBox" Width="70%" runat="server"></asp:TextBox>
                    <asp:Label ID="lblUserIn" runat="server" ForeColor="Red"></asp:Label>
                </td>
            </tr>
            <tr id="trPass" runat="server">
                <td style="width: 20%; height: 21px;text-align:right;padding-right:10px;height:30px" nowrap>
                    Mật khẩu <font color="red">*</font>:</td>
                <td style="width: 80%; text-align: left; height: 21px;;padding-left:5px" >
                    <asp:TextBox ID="txtPass" TextMode="Password"  onblur="CheckPass(this);" CssClass="cssTextBox" Width="70%" runat="server"></asp:TextBox>
                    <asp:Label ID="lblPassIn" runat="server" ForeColor="#CC3300"></asp:Label>
                </td>
            </tr>
            <tr  id="trPassC" runat="server">
                <td style="width: 20%; height: 21px;text-align:right;padding-right:10px;height:30px" nowrap>
                    Nhập lại mật khẩu <font color="red">*</font>:</td>
                <td style="width: 80%; text-align: left; height: 21px;;padding-left:5px" >
                    <asp:TextBox ID="txtPassC" onblur="CheckPassRep(this);" TextMode="Password" CssClass="cssTextBox" Width="70%" runat="server"></asp:TextBox>
                    <asp:Label ID="lblPassInRep" runat="server" ForeColor="#CC3300"></asp:Label>
                </td>
            </tr>
            <tr>
                <td style="width: 20%;text-align:right;padding-right:10px;height:30px"  nowrap>
                    Email <font color="red">*</font>:</td>
                <td style="width: 80%; text-align: left;padding-left:5px" > <asp:TextBox ID="txtEmail" onblur='CheckEmail(this)' CssClass="cssTextBox" Width="70%" runat="server"></asp:TextBox>
                    <asp:Label ID="lblEmailIn" runat="server" ForeColor="Red"></asp:Label>
                </td>
            </tr>
             <tr>
                <td style="width: 20%;text-align:right;padding-right:10px;height:30px"  nowrap>
                    Số điện thoại <font color="red">*</font>:</td>
                <td style="width: 80%; text-align: left;padding-left:5px" > <asp:TextBox ID="txtsdt" onblur="checkkytu(this);"  CssClass="cssTextBox" Width="70%" runat="server"></asp:TextBox>
                <asp:Label ID="lblsdtIn" runat="server" ForeColor="#CC3300"></asp:Label></td>
            </tr>
             <tr>
                <td style="width: 20%;text-align:right;padding-right:10px;height:30px"  nowrap>
                    Địa chỉ :</td>
                <td style="width: 80%; text-align: left;padding-left:5px" > <asp:TextBox ID="txtDiaChi" CssClass="cssTextBox" Width="70%" runat="server"></asp:TextBox></td>
            </tr>
             <tr>
                <td style="width: 20%;text-align:right;padding-right:10px;height:30px"  nowrap>
                    Giới tính :</td>
                <td style="width: 80%; text-align: left;padding-left:5px" >
                <asp:DropDownList ID="ddlSex" Width="250px"  CssClass="txtPass" Height="25px" runat="server">
                    <asp:ListItem Value="">--Chọn--</asp:ListItem>
                        <asp:ListItem Value="0">Nam</asp:ListItem>
                        <asp:ListItem Value="1">Nữ</asp:ListItem>
                        </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td style="width: 20%;text-align:right;padding-right:10px;height:30px"  nowrap>
                    Active:</td>
                <td style="width: 80%; text-align: left;padding-left:5px" >
                    <asp:DropDownList ID="ddlActive" runat="server" Width="200px" CssClass="cssDropDown">
                        <asp:ListItem Value="Y">Hiện</asp:ListItem>
                        <asp:ListItem Value="N">Ẩn</asp:ListItem>
                    </asp:DropDownList></td>
            </tr>           
            <tr>
                <td class="ActDocTD2" style="height: 30px">
                    &nbsp;</td>
                <td style="text-align: left; height: 21px;" align="center" class="ActDocTD3">
                    <asp:Button ID="btnSave" CssClass="button" runat="server" Text="Save"  OnClientClick="return fnSave();"
                       onclick="btnSave_Click"  Width="75px" />&nbsp;<asp:Button ID="btnCancel" 
                        CssClass="button" runat="server"
                            Text="Cancel" Width="75px" onclick="btnCancel_Click" /></td>
            </tr>
        </table>
        </center>
    </form>
    <script type="text/javascript">
        // kiểm tra kiểu số
        function checkkytu(e) {
            if (isNaN(e.value)) {
                e.value = "";
                document.getElementById("<%= lblsdtIn.ClientID%>").innerHTML = "phải là số !";
                e.select();
                return;
            }
            else {
                document.getElementById("<%= lblsdtIn.ClientID%>").innerHTML = "";
                if (e.value.length < 10 || e.value.length > 11)
                    document.getElementById("<%= lblsdtIn.ClientID%>").innerHTML = "số điện thoại không hợp lệ";
                else {
                    document.getElementById("<%= lblsdtIn.ClientID%>").innerHTML = "";
                    document.getElementById("<%= txtsdt.ClientID%>").className = "cssTextBox";
                }
            }
        }
        // kiểm tra họ tên
        function CheckName(obj) {
            if (document.getElementById("<%= txtTen.ClientID%>").value != "")
                document.getElementById("<%= txtTen.ClientID%>").className = "cssTextBox";
            if (document.getElementById("<%= txtTen.ClientID%>").value == "")
                document.getElementById("<%= txtTen.ClientID%>").className = "CssNotOk";
        }
          //kiểm tra user
         function CheckUser(obj) {
             if (document.getElementById("<%= txtuser.ClientID%>").value != "")
                 document.getElementById("<%= txtuser.ClientID%>").className = "cssTextBox";
         }
        //kiểm tra email
        function CheckEmail(obj) {
           
            if (isEmail(obj.value)) {
                document.getElementById("<%= lblEmailIn.ClientID%>").innerHTML = "";
            } else {
                document.getElementById("<%= lblEmailIn.ClientID%>").innerHTML = "Email không hợp lệ";
                return false;
            }
        }
        function isEmail(email) {
            var isValid = false;
            var regex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (regex.test(email)) {
                isValid = true;
            }
            return isValid;
        }
        //kiểm tra pass
        function CheckPass(obj) {
            var length = obj.value.length;
            if (length < 6)
                document.getElementById("<%= lblPassIn.ClientID%>").innerHTML = "Phải nhiều hơn 5 ký tự !";
            else {
                document.getElementById("<%= lblPassIn.ClientID%>").innerHTML = "";
                document.getElementById("<%= txtPass.ClientID%>").className = "CssNotOk";
            }

            var passRep = document.getElementById("<%= txtPass.ClientID%>").value;
            if (passRep != "") {
                if (obj.value == passRep) {
                    document.getElementById("<%= lblPassInRep.ClientID%>").innerHTML = "";
                    document.getElementById("<%= txtPass.ClientID%>").className = "cssTextBox";
                }
                else
                    document.getElementById("<%= lblPassInRep.ClientID%>").innerHTML = "mật khẩu phải giống nhau!";
            }

        }
        function CheckPassRep(obj) {
            var length = obj.value.length;
            var pass = document.getElementById("<%= txtPass.ClientID%>").value;
            if (obj.value != pass)
                document.getElementById("<%= lblPassInRep.ClientID%>").innerHTML = "mật khẩu phải giống nhau!";
            else {
                document.getElementById("<%= lblPassInRep.ClientID%>").innerHTML = "";
                document.getElementById("<%= txtPass.ClientID%>").className = "cssTextBox";
            }
        }


        // save data
        function fnSave() {       
            // kiểm tra họ tên        
            if (document.getElementById("<%= txtTen.ClientID%>").value == "") {
                document.getElementById("<%= txtTen.ClientID%>").className = "CssNotOk";
                return false;
            }
            // kiểm tra user đăn nhập
            if (document.getElementById("<%= txtuser.ClientID%>").value == "") {
                document.getElementById("<%= txtuser.ClientID%>").className = "CssNotOk";
                return false;
            }

            // kiểm tra email
            if (document.getElementById("<%= txtEmail.ClientID%>").value == "") {
                document.getElementById("<%= txtEmail.ClientID%>").className = "CssNotOk";
                return false;
            }
          
            var email = document.getElementById("<%= txtEmail.ClientID%>").value;
            if (isEmail(email)) {
                document.getElementById("<%= lblEmailIn.ClientID%>").innerHTML = "";
            }
            else {
                document.getElementById("<%= lblEmailIn.ClientID%>").innerHTML = "Email không hợp lệ";
                return false;
            }

            // kiểm tra mật khẩu
            if (document.getElementById("<%= txtPass.ClientID%>").value == "" || document.getElementById("<%= lblPassIn.ClientID%>").innerHTML != "") {
                document.getElementById("<%= txtPass.ClientID%>").className = "CssNotOk";
                return false;
            }
            if (document.getElementById("<%= txtPassC.ClientID%>").value == "" || document.getElementById("<%= lblPassInRep.ClientID%>").innerHTML != "") {
                document.getElementById("<%= txtPassC.ClientID%>").className = "CssNotOk";
                return false;
            }

        }

    </script>
</body>
</html>
